package com.xuelang.pipeline.artifact.app.nexus3v1.fallback;

import com.xuelang.pipeline.artifact.app.nexus3v1.RepositoryFolderService;
import com.xuelang.pipeline.artifact.app.nexus3v1.request.DeleteRepositoryFolderRequest;
import com.xuelang.pipeline.artifact.app.nexus3v1.response.DeleteRepositoryFolderResponse;
import com.xuelang.pipeline.artifact.client.common.constant.ArtifactConstant;
import org.springframework.cloud.openfeign.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author xiwen.zxg
 * @since 2024/7/10
 */
@Slf4j
@Service
public class RepositoryFolderServiceFallbackFactory implements FallbackFactory<RepositoryFolderService> {

    @Override
    public RepositoryFolderService create(Throwable throwable) {
        log.error("{} happened to exception with {}", this.getClass().getName(), throwable.getMessage());
        return new RepositoryFolderService() {

            @Override
            public DeleteRepositoryFolderResponse deleteFolder(DeleteRepositoryFolderRequest deleteRepositoryFolderRequest) {
                DeleteRepositoryFolderResponse deleteRepositoryFolderResponse = new DeleteRepositoryFolderResponse();
                deleteRepositoryFolderResponse.setTid(ArtifactConstant.DEFAULT_ERROR_CODE);
                deleteRepositoryFolderResponse.setAction(ArtifactConstant.DEFAULT_ERROR_MSG);
                deleteRepositoryFolderResponse.setMethod(ArtifactConstant.DEFAULT_ERROR_MSG);
                deleteRepositoryFolderResponse.setType(ArtifactConstant.DEFAULT_ERROR_MSG);
                deleteRepositoryFolderResponse.setResult(DeleteRepositoryFolderResponse.ResultXO.builder().success(false).data(null).build());
                return deleteRepositoryFolderResponse;
            }
        };
    }
}
